<?php

/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/3/25
 * Time: 17:55
 */
class Model_Prized extends PhalApi_Model_NotORM{
  protected function getTableName($id){
    return 't_prized';    //用户抽奖纪录
  }
/*
 * 今天的抽奖次数
 */
  public function getPrizedTimes($userid){
    return $this->getORM()->select('count(*) count')
      ->where('userid',$userid)
      ->where('createtime<?',strtotime(date("Y-m-d",strtotime("+1 day"))))
      ->where('createtime>=?',strtotime(date("Y-m-d")))
      ->fetchOne();
  }

  /*
   * 获取今天是否中奖
   */
  public function getTodayGift($userid){
    return $this->getORM()->select('count(*) count')
      ->where('createtime<?',strtotime(date("Y-m-d",strtotime("+1 day"))))
      ->where('createtime>=?',strtotime(date("Y-m-d")))
      ->where('isprized',1)
      ->where('userid',$userid)
      ->fetchOne();
  }

  /**
   * 插入抽奖纪录
   */
  public function InsertPrized($userid,$isPrized){
    $this->getORM()->insert(array('userid'=>$userid,'isprized'=>($isPrized?1:0),'createtime'=>time()));
  }
}